﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.CMS.MODEL;
using Jxym.wlkc2011.Module.CMS.Public;
using System.Web.UI.HtmlControls;

namespace Jxym.wlkc2011
{
    public partial class video : System.Web.UI.Page
    {
        public string _contentHtml = "暂无信息";
        public string _videoTitle = "info";

        private string contentClassID;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["siteName"] != null)
                {
                    siteName = Request.Params["siteName"];

                    MsSqlDal<Cms_Site> site = new MsSqlDal<Cms_Site>();

                    Cms_Site Info = site.GetModel("Name='" + siteName + "'", null);

                    if (Info != null)
                    {
                        tempName = Info.TemplateName;

                        HtmlGenericControl scriptControl = new HtmlGenericControl("script");
                        scriptControl.Attributes.Add("type", "text/javascript");
                        scriptControl.Attributes.Add("src", "Module/CMS/resources/templates/" + Info.TemplateName + "/Scripts/prototype_video.js");
                        Page.Header.Controls.Add(scriptControl);

                        HtmlGenericControl scriptControl1 = new HtmlGenericControl("script");
                        scriptControl1.Attributes.Add("type", "text/javascript");
                        scriptControl1.Attributes.Add("src", "Module/CMS/resources/templates/" + Info.TemplateName + "/Scripts/effects_video.js");
                        Page.Header.Controls.Add(scriptControl1);

                        HtmlGenericControl scriptControl2 = new HtmlGenericControl("script");
                        scriptControl2.Attributes.Add("type", "text/javascript");
                        scriptControl2.Attributes.Add("src", "Module/CMS/resources/templates/" + Info.TemplateName + "/Scripts/glider_video.js");
                        Page.Header.Controls.Add(scriptControl2);
                    }
                }
                if (Request.Params["menu"] != null)
                {
                    menuId = Request.Params["menu"];
                }

                if (Request.Params["content"] != null)
                {
                    contentClassID = Request.Params["content"];
                    LoadContent(contentClassID);
                }
                else
                {
                    MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();

                    IList<Cms_ContentClass> cccList = ccc.GetList("ParentID=" + menuId, null, "", 0);

                    if (cccList.Count > 0)
                    {
                        LoadContent(cccList[0].ID.ToString());
                    }
                }
            }
        }

        private void LoadContent(string _contentClassID)
        {
            MsSqlDal<Cms_Content> cct = new MsSqlDal<Cms_Content>();

            Cms_Content info = cct.GetModel("ContentClassID=" + _contentClassID, null);

            if (info != null)
            {
                if (info.VideoFileName != "" && info.VideoFileName != "no.flv")
                {
                    _videoTitle = info.Title;
                    _contentHtml = cmsPublic.ViewContentByFileType(Request.Params["siteName"], info.VideoFileName, info.ViewPhoto, "640", "360", false);
                }
            }

            LoadList();
        }

        private void LoadList()
        {
            MsSqlDal<Cms_Site_ContentClass> cscc = new MsSqlDal<Cms_Site_ContentClass>();

            IList<Cms_Site_ContentClass> csccList = cscc.GetList("siteName='" + siteName + "'", null, "", 0);

            foreach (Cms_Site_ContentClass csccInfo in csccList)
            {
                MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();

                Cms_ContentClass cccInfo = ccc.GetModel(csccInfo.ContentClassID);

                if (cccInfo != null && cccInfo.Title == "课程学习")
                {
                    IList<Cms_ContentClass> cccList = ccc.GetList("ParentID=" + cccInfo.ID, null, "Sort", 0);

                    string where = "";

                    foreach (Cms_ContentClass cccInfo1 in cccList)
                    {
                        where += "or ContentClassID=" + cccInfo1.ID;
                    }

                    where = where.TrimStart("or ".ToCharArray());

                    MsSqlDal<Cms_Content> cc = new MsSqlDal<Cms_Content>();

                    Repeater1.DataSource = cc.GetList(where, null, "AddTime DESC", 0);
                    Repeater1.DataBind();

                    break;
                }
            }
        }

        public string siteName { get; set; }

        public string menuId { get; set; }

        public string tempName { get; set; }
    }
}